/*
 * @(#)ShowOfflineSql.java   1.0  2022年3月27日
 * 
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.dts.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swift.core.model.ServiceRequest;
import com.swift.core.model.data.DataModel;
import com.swift.core.model.data.MapDataModel;
import com.swift.core.service.SynInterface;
import com.swift.dts.dao.OfflineSqlTableDao;
import com.swift.dts.dao.model.OfflineSqlTable;
import com.swift.dts.dao.model.SynObjectKey;
import com.swift.util.date.DateUtil;

/**
 * 添加说明 
 * @author zhengjiajin
 * @version 1.0 2022年3月27日
 */
@Service("showOfflineSql")
public class ShowOfflineSql implements SynInterface{
    //private static final Logger log = LoggerFactory.getLogger(ShowOfflineSql.class);
    @Autowired
    private OfflineSqlTableDao offlineSqlTableDao;
    
    
    /** 
     * @see com.swift.core.service.SynInterface#doService(com.swift.core.model.ServiceRequest)
     */
    @Override
    public DataModel doService(ServiceRequest req) {
        SynObjectKey key = new SynObjectKey();
        Boolean exec = req.getData().getBoolean("dosql");
        String destination = req.getData().getString("destination");
        String dataSource = req.getData().getString("dataSource");
        String dbName = req.getData().getString("dbName");
        String tableName = req.getData().getString("tableName");
        key.setDestination(destination);
        key.setDataSource(dataSource);
        key.setDbName(dbName);
        key.setTableName(tableName);
        
        DataModel res = new MapDataModel();
        List<OfflineSqlTable> list = offlineSqlTableDao.list(key);
        if(list!=null) {
            res.addObject("listcount", list.size());
        }
        if(exec!=null && exec) {
            offlineSqlTableDao.delete(key);
        }
        return res;
    }
    
    public static void main(String[] args) {
        //11:01:49,772 2022-03-28 18:23:21
        System.out.println(DateUtil.formatDate(new Date(1648469351000l)));
    }

}
